﻿@using KRM.Core
@using KRM.Core.Library
@model List<KRM.Core.vOrderView_OrderItemParts>
@{
    var orderitemid = ViewBag.Orderitemid;
}
<a href="#warehouse" role="button" data-toggle="modal" id="choosewarehouse"></a>

<table class="table table-hover table-bordered table-fix krmtable" data-height="300">
    <thead>
        <tr>
            <th></th>
            <th>Action</th>
            <th>LoadItemStatus</th>
            <th>DeliveryType</th>
            <th>Qty</th>
            <th>PartID</th>
            <th>PartName</th>
            <th>IsOptional</th>
            <th>SupplierManufacturer</th>
            <th>WareHouse</th>
            <th>CarrierService</th>
            <th>StockAllocatedDate</th>
            <th>LoadName</th>
            <th>DriveName</th>
            <th>DropNumber</th>
            <th>DatePicker</th>
            <th>OrderItemID</th>
            <th>SentStockID</th>
            <th>PartVersion</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.Partial("Partial/OrderView/ajax/_OrderItemPartDetails",item)</td>
                <td class="padding10" style="max-width: none;overflow: visible;">
                    <div class="btn-group">
                        <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><span class="caret"></span></a>
                        <ul class="dropdown-menu dropdowm-right">
                            @if (item.StockHeld.Value)
                            {
                                <li>
                                    <a href="javascript:;" onclick="ReleaseQtyXPartnameSentstock(@item.OrderItemID, @item.SentStockID)" >Release 1x @item.PartName (@item.SentStockID)</a>
                                </li>
                            }
                            
                            @if (item.CustomerWaitingForPartID > 0)
                            {
                                <li>
                                    <a href="javascript:;" onclick="removeFromBackOrder(@item.OrderItemPartID, @item.CustomerWaitingForPartID)" >Remove From Back Order</a>
                                </li>
                            }
                            else
                            {
                                if (item.StockSent.HasValue && !item.StockSent.Value && Users.Current(User.Identity.Name).HasPermission(Permissions.CanAddBackOrders))
                                {
                                    <li>
                                        <a href="javascript:;" onclick="removepartfromfeedandadd(@item.OrderItemPartID)" >Remove part from feed and add to back order</a>
                                    </li>
                                }
                            }
                            <li>
                                <a href="javascript:;" onclick="PopupCenter('/orderview/viewpullbackaudit?orderitempartid=@item.OrderItemPartID', 800, 500)" >View Pull Back Audit</a>
                            </li>
                            <li>
                                <a href="javascript:;" onclick="PopupCenter('/orderview/viewmovecourieraudit?orderitempartid=@item.OrderItemPartID', 800, 500)" >View Move Courier Audit</a>
                            </li>
                            <li>
                                <a href="javascript:;" onclick="PopupCenter('/orderview/viewchangewarehouseaudit?orderitempartid=@item.OrderItemPartID', 800, 500)" >View Change Warehouse Audit</a>
                            </li>
                            @if (!item.Dispatched.HasValue && (item.IsStocked??false))
                            {
                                <li>
                                    <a href="javascript:;" onclick="holdpart(@item.SentStockID, @item.OrderItemPartID)" >Hold Part</a>
                                </li>
                            }
                            else
                            {
                                <li>
                                    <a href="javascript:;" onclick="alert('Cannot Hold Part. The part is either already Dispatched or not in stock.')">Hold Part</a>
                                </li>
                            }
                            <li>
                                <a href="javascript:;" onclick="@(!string.IsNullOrEmpty(item.LoadName) ? "PopupCenter('/orderview/viewloadplanningaudit?orderitempartid=" + item.OrderItemPartID + "',800,500)" : "alert('Item is not in a load or has been removed from a load.')")" >View Load Planning Audit</a>
                            </li>
                        </ul>
                    </div>
                </td>
                <td>@item.LoadItemStatus</td>
                <td>@item.DeliveryType</td>
                <td>@item.Qty</td>
                <td>@item.PartID</td>
                <td>@item.PartName</td>
                <td style="text-align: center"><input type="checkbox" disabled="disabled" @(item.IsOptional ? "checked=checked" : "")/></td>
                <td>@item.Supplier_Manufacturer</td>
                <td>@item.Warehouse</td>
                <td>@item.CarrierService</td>
                <td>@item.StockAllocatedDate</td>
                <td>@item.LoadName</td>
                <td>@item.DriverName</td>
                <td>@item.DropNumber</td>
                <td>@item.DatePicked</td>
                <td>@item.OrderItemID</td>
                <td>@item.SentStockID</td>
                <td>@item.PartVersion</td>
            </tr>
        }
    </tbody>
</table>
<input type="button" class="btn btn-primary" value="Edit Parts" onclick="PopupCenter('/orderview/editpartsinorderitem?orderitemid=@orderitemid',900,600);" style="margin-top: 10px" />